/**
*  \file control_dcdc.c
*
*  \brief
*
*  \author Michael J. Hohmann  <michael.hohmann@linde-mh.de>
*
*
*/

/*===============================================[ private includes  ]================================================*/
#include "control_dcdc.h"
#include "../assertor/assertor.h"
#include "../pal/pal_mem.h"

/*===============================================[ private defines   ]================================================*/

/*===============================================[ private datatypes ]================================================*/

/** Private variables */
struct control_dcdc_private
{
   BO   dcdc_current_state;
   S16  dcdc_delay_counter;
};

/*===============================================[ private variables ]================================================*/
static struct control_dcdc_private control_dcdc;

/*===============================================[ private functions ]================================================*/

/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
RC control_dcdc_initialize( void )
{
   pal_memzero( &control_dcdc, sizeof control_dcdc);

   return RC_SUCCESS;
}

/*
* Check here all conditions that prevent sleeping.
*
*
*	conditions for sleep may be:
*	speed < 0.1
*	no driver present
*	no writing in eeprom ( dtc cwt ...)
*	fans are off.
*	parking brake
*   dc-link voltage low
*   ...
*
*  \return TRUE if ECU should stay alive. FALSE will switch off ECU
*/
BO control_dcdc_10ms(S16 key_switch,BO precharge, F32 direct_link_voltage, F32 battery_voltage,U16 DELAY_TIMER)
{
 
    if(control_dcdc.dcdc_current_state == FALSE)
    {
        if(key_switch > 5)  //open the switch
        {
             control_dcdc.dcdc_current_state = TRUE;
        }
        else
        {
            control_dcdc.dcdc_current_state = FALSE;
        }
    }
    else if(control_dcdc.dcdc_current_state == TRUE) 
    {
        if(key_switch <-5 )
        {
            control_dcdc.dcdc_delay_counter++;     // when the switch off ,the dc-dc delay 5s;
            if(control_dcdc.dcdc_delay_counter > DELAY_TIMER)  
            {
                control_dcdc.dcdc_delay_counter = 0;
                control_dcdc.dcdc_current_state = FALSE;
            }
        }
		else if(key_switch > 5)  //open the switch
		{
			control_dcdc.dcdc_delay_counter = 0;
		}
    }
	
    return control_dcdc.dcdc_current_state;
}

/*===============================================[ private functions ]================================================*/


/***********************************************************************************************************************
*                             Copyright 2020 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
